package psrc.logic.pages.rede;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import psrc.logic.pages.base.ControllerBase;
import psrc.logic.util.beans.RedeBean;

public class SendRedeRemoveController extends ControllerBase {

	private static final long serialVersionUID = 1L;

	String[] redeCheckbox;

	@Override
	public String executeController() throws Exception {
		RedeModel model = new RedeModel();
		List<RedeBean> todosRedes = model.getRedesList();
		List<RedeBean> redesParaRemover = new ArrayList<RedeBean>();
		List<String> idsParaRemover = Arrays.asList(getRedeCheckbox());

		for (RedeBean prod : todosRedes) {
			if (idsParaRemover.contains(prod.getIdRede())) {
				redesParaRemover.add(prod);
			}
		}
		try {
			if (model.removeRede(redesParaRemover)) {
				return SUCCESS;
			}
		} catch (Exception e) {
			addActionError(getText("error.constraint"));
		}
		return ERROR;
	}

	/**
	 * @return the redeCheckbox
	 */
	public String[] getRedeCheckbox() {
		return redeCheckbox;
	}

	/**
	 * @param redeCheckbox
	 *            the redeCheckbox to set
	 */
	public void setRedeCheckbox(String[] redeCheckbox) {
		this.redeCheckbox = redeCheckbox;
	}



}
